<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="./js/vue.js"></script>
    <style>
        #app {
            margin: auto;
            width: 400px;
            border: 1px solid black;
        }

        .app1 {
            margin: auto;
            width: 300px;
            margin: 20px 70px;
        }

        .app2 {
            margin: auto;
            margin-bottom: 20px;
            width: 200px;
            height: 400px;
        }

        li {
            width: 170px;
            margin-left: -20px;
        }

        .fork {
            color: red;
        }

        .content {
            width: 150px;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="app1">
            <input v-model="msg" />
            <button @click='list'>添加</button>
        </div>
        <div class="app2">
            <ol>
                <li is='list-item' v-for='(list,index) in lists' v-bind:key='list.id' v-bind:title='list.title' v-on:remove='lists.splice(index,1)'></li>
            </ol>

        </div>
    </div>
    <script>
        Vue.component('list-item', {
            template: '\
            <li>\
            <div class="content">{{ title }}</div>\
            <span class="fork" v-on:click="$emit(\'remove\')">x</span>\
            </li>\
            ',
            props: ['title']
        })

        let vm = new Vue({
            el: '#app',
            data: {
                msg: '',
                lists: [
                    { id: 1, title: '我最美' },
                ],
                next: 5
            },
            methods: {
                list: function () {
                    this.lists.push({
                        id: this.next++,
                        title: this.msg
                    })
                    this.msg = '我最美';
                }
            }
        })

    </script>
</body>

<html>